package com.cn.mmd.controller;

import com.cn.mmd.model.LogManage;
import com.cn.mmd.model.LogStudent;
import com.cn.mmd.model.LogTeacher;
import com.cn.mmd.service.LogManageService;
import com.cn.mmd.service.LogStudentService;
import com.cn.mmd.service.LogTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2016/8/16 0016.
 */

@Controller
public class LogController{

    @Autowired
    private LogStudentService logStudentService;

    @Autowired
    private LogTeacherService logTeacherService;

    @Autowired
    private LogManageService logManageService;

    public synchronized void logManage(String log,String id){
        Date date = new Date();
        SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String logTime = time.format(date);
        LogManage logManage = new LogManage();
        logManage.setLogtime(logTime);
        logManage.setManageid(id);
        logManage.setLogcontent(log);

       logManageService.insertSelective(logManage);
    }

    public synchronized void logStudent(String log,String id){
        Date date = new Date();
        SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String logTime = time.format(date);
        LogStudent logStudent = new LogStudent();
        logStudent.setLogtime(logTime);
        logStudent.setLogcontent(log);
        logStudent.setStudentid(id);
        logStudentService.insertSelective(logStudent);
    }

    public synchronized void logTeacher(String log,String id){
        Date date = new Date();
        SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String logTime = time.format(date);
        LogTeacher logTeacher = new LogTeacher();
        logTeacher.setLogtime(logTime);
        logTeacher.setLogcontent(log);
        logTeacher.setTeacherid(id);
        logTeacherService.insertSelective(logTeacher);
    }
}
